#!/bin/bash

# run this as:
#    sudo docker run -d shark-worker:${SHARK_VERSION} ${MASTER_IP} spark://${MASTER_IP}:7077

source /root/shark_files/configure_shark.sh

IP=$(ip -o -4 addr list eth0 | perl -n -e 'if (m{inet\s([\d\.]+)\/\d+\s}xms) { print $1 }')
echo "WORKER_IP=$IP"

echo "preparing Shark"
prepare_shark $1

echo "starting Hadoop datanode"
service hadoop-datanode start

echo "starting sshd"
/usr/sbin/sshd

sleep 5

echo "starting Shark worker node"
cp /root/shark_worker_files/run_shark_worker.sh /
chmod a+rx /run_shark_worker.sh
sudo -u hdfs SPARK_VERSION=$SPARK_VERSION SHARK_VERSION=$SHARK_VERSION /run_shark_worker.sh
